//
//  UIImage+FZExtension.swift
//  FZSina_Swift
//
//  Created by 李忠 on 7/20/16.
//  Copyright © 2016 FZLZ. All rights reserved.
//

import UIKit
import SDWebImage
extension UIImageView{
    convenience init(imgNamed: String) {
        
        self.init(image: UIImage(named: imgNamed))
    }
    
    //通过SDWebImage 设置头像
    func fz_setImage(urlString: String, placeholderImgName: String = "avatar_default_big") {
        let url = NSURL(string: urlString)
        
        self.sd_setImageWithURL(url, placeholderImage: UIImage(named: placeholderImgName))
       
    }
    
    func fz_downloadIMG(urlString: String, placeholder: String) {
        
        let url = NSURL(string: urlString)
        self.image = UIImage(named: placeholder)
        
        SDWebImageManager.sharedManager().downloadImageWithURL(url, options: SDWebImageOptions.ProgressiveDownload, progress: nil) { (image, error, type, _, url) in
            
            let scale = UIScreen.mainScreen().scale
            let data = UIImageJPEGRepresentation(image, scale)
            let image = UIImage(data: data!)
    
            self.image = image
            
            
            
            
        }
        
    }
}
    
